package com.ruoyi.paymentConfig.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.paymentConfig.domain.PaymentConfig;
import com.ruoyi.paymentConfig.service.IPaymentConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 缴费配置Controller
 *
 * @author ch
 * @date 2022-03-11
 */
@RestController
@RequestMapping("/paymentConfig/paymentConfig")
public class PaymentConfigController extends BaseController
{
    @Autowired
    private IPaymentConfigService paymentConfigService;

    /**
     * 查询缴费配置列表
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(PaymentConfig paymentConfig)
    {
        startPage();
        List<PaymentConfig> list = paymentConfigService.selectPaymentConfigList(paymentConfig);
        return getDataTable(list);
    }

    /**
     * 导出缴费配置列表
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:export')")
    @Log(title = "缴费配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PaymentConfig paymentConfig)
    {
        List<PaymentConfig> list = paymentConfigService.selectPaymentConfigList(paymentConfig);
        ExcelUtil<PaymentConfig> util = new ExcelUtil<PaymentConfig>(PaymentConfig.class);
        return util.exportExcel(list, "缴费配置数据");
    }

    /**
     * 获取缴费配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(paymentConfigService.selectPaymentConfigById(id));
    }

    /**
     * 新增缴费配置
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:add')")
    @Log(title = "缴费配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaymentConfig paymentConfig)
    {
        return toAjax(paymentConfigService.insertPaymentConfig(paymentConfig));
    }

    /**
     * 修改缴费配置
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:edit')")
    @Log(title = "缴费配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaymentConfig paymentConfig)
    {
        paymentConfig.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(paymentConfigService.updatePaymentConfig(paymentConfig));
    }

    /**
     * 删除缴费配置
     */
    @PreAuthorize("@ss.hasPermi('paymentConfig:paymentConfig:remove')")
    @Log(title = "缴费配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paymentConfigService.logicDeletePaymentConfig(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
